package cn.cs.service;

import cn.cs.mapper.CsUserMapper;
import cn.cs.pojo.CsUser;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * yuexl
 */
@RestController
public class RestCsUserService {

    //@Autowired
    @Resource
    private CsUserMapper csUserMapper;

    @RequestMapping(value = "/getCsUserById", method = RequestMethod.POST)
    public CsUser getDmUserById(@RequestParam("id") Long id) throws Exception {
        return csUserMapper.getCsUserById(id);
    }

    @RequestMapping(value = "/getCsUserListByMap", method = RequestMethod.POST)
    public List<CsUser> getCsUserListByMap(@RequestBody Map<String, Object> param) throws Exception {
        return csUserMapper.getCsUserListByMap(param);
    }

    @RequestMapping(value = "/getCsUserCountByMap", method = RequestMethod.POST)
    public Integer getCsUserCountByMap(@RequestBody Map<String, Object> param) throws Exception {
        return csUserMapper.getCsUserCountByMap(param);
    }

    @RequestMapping(value = "/checkLoginByPassword", method = RequestMethod.POST)
    public CsUser checkLoginByPassword(@RequestBody CsUser csUser) throws Exception {
        return csUserMapper.checkLoginByPassword(csUser.getPhone(), csUser.getPassword());
    }

    @RequestMapping(value = "/qdtxAddCsUser", method = RequestMethod.POST)
    @Transactional
    public Integer qdtxAddCsUser(@RequestBody CsUser csUser) throws Exception {
        csUser.setCreatedTime(new Date());
        return csUserMapper.insertCsUser(csUser);
    }

    @RequestMapping(value = "/qdtxModifyCsUser", method = RequestMethod.POST)
    @Transactional
    public Integer qdtxModifyCsUser(@RequestBody CsUser csUser) throws Exception {
        csUser.setUpdatedTime(new Date());
        return csUserMapper.updateCsUser(csUser);
    }

    @RequestMapping(value = "/findByWxUserId", method = RequestMethod.POST)
    public CsUser findByWxUserId(@RequestParam("wxUserId") String wxUserId) throws Exception {
        return csUserMapper.findByWxUserId(wxUserId);
    }

    @RequestMapping(value = "/createCsUser")
    @Transactional
    public Integer createCsUser(@RequestBody CsUser csUser) throws Exception {
        csUser.setCreatedTime(new Date());
        return csUserMapper.insertCsUser(csUser);
    }
}
